package nc2db;
import nc2grd.NC2Grd;
import grib2db.grd2array;
import java.util.List;
import java.util.ArrayList;
public class ncArray {
	public float[][][][] getNCarray(String grddir,int longitude,int latitude,int layer) {
		grd2array gy = new grd2array();
		FileName2year Fr= new FileName2year();
		int year = Fr.file2year(grddir);
		LeapYear LY = new LeapYear();
		int time;
		if(LY.isLeapYear(year))
	    {
			time = 366;
		}
		else
		{
			time = 365;
		}
		int datalens=longitude*latitude*layer*time;
		float data[] = gy.getArray(datalens,grddir);
		float[][][][] NCdata = new float[longitude][latitude][layer][time];
		int m = 0;
		for(int n =0;n<time;n++)
	    {
		    for (int i = 0; i < layer; i++) 
		    {
			   for (int j = 0; j < latitude; j++) 
			   {
				    for (int k = 0; k < longitude; k++) 
				    {
					  NCdata[k][j][i][n] = data[m];
					  m++;
				    }
			   }
		    }
	    }
		
		return NCdata;//*/
	}

	public static void main(String[] args) {
		
		// NC2Grd testT = new NC2Grd("/gpfs/home/css/liuxs/ftp/download/","/gpfs/home/css/liuxs/NC2Grd/nc2grd.ncl");
		// ArrayList<String> t = testT.GetGrd("air", "daily");
		// for(String s: t){
		    // System.out.println(s);
			// FileName2year Fr= new FileName2year();
			// int year = Fr.file2year(s);
			// System.out.println(year);
			// ncArray ny = new ncArray();
		// float[][][][] NCdata = ny.getNCarray(s,144,73,17);
		
		// Array2db A2b = new Array2db();
		// int a = A2b.data2db(NCdata,year,1,"java","element");//给要素库灌数据
		// //System.out.println(NCdata[23][56][5][4]);
		// //System.out.println(a);
		// }
		
	}
}
